#ifndef TRANSACTION
#define TRANSACTION

/* Transaction
*************************************************************************************
*
*   Does not resize
*
*************************************************************************************
*
*   Credits
*
*		Richard Rios
*		Aaron Solomon
*
*************************************************************************************
*/
	#include <fstream>

	#include "Inventory.h"
	#include "Product.h"

	using namespace std;
/*
*************************************************************************************/

class Transaction {
	/*************************************************************************************
	*
	*	Fields
	*/
	public:
		static const int ERR_INVALID_AMOUNT				= 1;
		static const int ERR__OPEN_FILE					= 2;
		static const int ERR__MOD_CLOSED_TRANSACTION	= 3;

	private:
		static const float SALES_TAX; //7.5%

		float tax;					  //total tax ($)
		float subtotal;				  //total price w/o tax
									  //total = tax + subtotal

		bool transactionOpen;		  //is the transaction open?
		
		Inventory* inventory;		  //inventory, or rather store catalog of items
		ofstream file;				  //file that the receipt is written to
	/*
	*************************************************************************************
	*
	*	Constructors
	*/
	public:
		Transaction(char* filename, Inventory* inventory);
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Opens a file of filename for writing and stores inventory for calculating prices.
		*
		*		The transaction contains all items and their quantities involved in the transaction, the
		*		subtotal, the tax, and the total. The receipt is the printout of the transaction.
		*
		*   Takes
		*   -----------------------
		*
		*       char* filename
		*			-	file to be opened (receipt file)
		*
		*		Inventory* inventory
		*			-	catalog of item prices
		*
		*   Returns
		*   -----------------------
		*
		*       Transaction
		*
		*/
	/*
	*************************************************************************************
	*
	*	Destructor
	*/
		~Transaction();
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Closes receipt file
		*
		*   Takes
		*   -----------------------
		*
		*		nothing
		*
		*   Returns
		*   -----------------------
		*
		*       nothing
		*
		*/
	/*
	*************************************************************************************
	*
	*	Properties
	*
	*		Setters
	*/
			/* none */
	/*
	**************************************************************************************
	*
	*		Getters
	*/
		float getTax();
		float getSubtotal();
	/*
	*************************************************************************************
	*
	*	Methods
	*/
		void addItem(int productNumber, int amount);
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Adds an item to the transaction (sale of item). The item is looked up in the inventory, the
		*		price of item * amount of item is added to subtotal, the price of item * amount of item * (1 - tax rate) is
		*		added to tax, and then item's description and quantity are written to the receipt.
		*
		*   Takes
		*   -----------------------
		*
		*       int productNumber
		*			-	item in question (get item via inventory.find(productNumber))
		*
		*		int amount
		*			-	quantity of item
		*
		*   Returns
		*   -----------------------
		*
		*       boolean signifying whether item was successfully added or not
		*
		*/

		float calculateTotal();
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Calculates the total money involved in the transaction
		*
		*			total = subtotal + tax
		*
		*   Takes
		*   -----------------------
		*
		*		nothing
		*
		*   Returns
		*   -----------------------
		*
		*       float (total)
		*
		*/

		void endTransaction();
		/*
		*
		*   Description
		*   -----------------------
		*
		*       Ends the transaction and writes final information like subtotal, tax, and total
		*		to the file.
		*
		*   Takes
		*   -----------------------
		*
		*		nothing
		*
		*   Returns
		*   -----------------------
		*
		*       float (total)
		*
		*/
	/*
	*************************************************************************************/
}; //class Transaction

#endif